package com.kara.woodAgent.common.model;

import com.kara.woodAgent.common.enums.ResultCodeEnum;
import lombok.Data;


/**
 * @author szht
 * @version 1.0
 * @project tiny-admin
 * @description 返回
 * @date 2024/10/11 10:39:01
 */
@Data
public class Result<T > {


	private String msg;

	private int code;

	private T data;

	public Result(RuntimeException e) {
		this.msg = e.getMessage();
		this.code = ResultCodeEnum.ERROR.getCode();
	}

	public Result(String msg, int code, T data) {
		this.msg = msg;
		this.code = code;
		this.data = data;
	}



	public static Result<Void> ok() {
		return new Result<>("success", ResultCodeEnum.SUCCESS.getCode(), null);
	}

	public static <T> Result<T> ok(T data) {
		return new Result<T>("success", ResultCodeEnum.SUCCESS.getCode(), data);
	}

	public static <T> Result<T> ok(String msg, T data) {
		return new Result<T>(msg, ResultCodeEnum.SUCCESS.getCode(), data);
	}

	public static Result<Void> error(RuntimeException e) {
		return new Result<>(e);
	}

	public static Result<Void> error(String msg) {
		return new Result<>(msg, ResultCodeEnum.ERROR.getCode(), null);
	}

	public static Result<Void> error(Integer code,String msg) {
		return new Result<>(msg,code, null);
	}

	public static Result<Void> msg(String msg) {
		return new Result<>(msg, ResultCodeEnum.SUCCESS.getCode(), null);
	}

}
